package com.spzx.report.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.report.service.SpzxReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
//@RequestMapping("report")
public class SpzxReportController extends BaseController {

    @Autowired
    SpzxReportService spzxReportService;

    @GetMapping("getAiReport/{question}")
    public AjaxResult getAiReport(@PathVariable String question) {
        Map<String, Object> reportMaps = spzxReportService.getAiReport(question);
        return success(reportMaps);
    }

    @GetMapping("getDataReport/{answerToken}")
    public AjaxResult getDataReport(@PathVariable String answerToken) {
        Map<String,Object> xyMap = new HashMap<>();
        List<Object> xList = new ArrayList<>();
        List<Object> yList = new ArrayList<>();
        List<Map<String, Object>> xyMaps = spzxReportService.getDataReport(answerToken);
        for (Map<String, Object> map : xyMaps) {
            Object xMap = map.get("groupTag");
            Object yMap = map.get("count");
            xList.add(xMap);
            yList.add(yMap);
        }
        xyMap.put("xList",xList);
        xyMap.put("yList",yList);
        return AjaxResult.success(xyMap);
    }

}